package com.tg.appcommon.android;
import android.graphics.Typeface;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.SpannedString;
import android.text.style.AbsoluteSizeSpan;
import android.widget.EditText;

public class FontUtil {
    public static Typeface getBlackItaltc() {
        return Typeface.createFromAsset(TGApplicationBase.getApplicationContext().getAssets(), "fonts/DIN-BLACKITALIC.ttf");
    }

    public static Typeface getMedium() {
        return Typeface.createFromAsset(TGApplicationBase.getApplicationContext().getAssets(), "fonts/DIN-MEDIUM.ttf");
    }

    public static void SetEditTextHintFontSize(EditText editText, int size, int contentID) {
        String content = ResourcesUtil.getString(contentID);
        SetEditTextHintFontSize(editText, size, content);
    }

    public static void SetEditTextHintFontSize(EditText editText, int size, String content) {
        // 新建一个可以添加属性的文本对象
        SpannableString ss = new SpannableString(content);
        // 新建一个属性对象,设置文字的大小
        AbsoluteSizeSpan ass = new AbsoluteSizeSpan(size, true);
        // 附加属性到文本
        ss.setSpan(ass, 0, ss.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        // 设置hint
        editText.setHint(new SpannedString(ss)); // 一定要进行转换,否则属性会消失
    }

    public static void SetEditTextHintFontSize(EditText editText, int size) {
        // 新建一个可以添加属性的文本对象
        String content = editText.getHint().toString();
        SetEditTextHintFontSize(editText, size, content);
    }
}
